package hotel;

import java.awt.GridLayout;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.GregorianCalendar;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class FinestraStatistiche extends JFrame{
	private ResultSet rs=null;
	private JPanel pannello;
	private JTextField numClienti,numClientiAnno,numClientiAnnoP,numClientiProv;
	private JLabel clienti,clientiAnno,clientiAnnoP,clientiProv;
	private GregorianCalendar gc = new GregorianCalendar();
	private String annoCorrente=Integer.toString(gc.get(GregorianCalendar.YEAR));
	private String annoPrecedente=Integer.toString(gc.get(GregorianCalendar.YEAR)-1);

	public FinestraStatistiche(){
		setSize(400,300);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setLocation(350, 250);
		setResizable(false);
		this.setVisible(true);
		pannello = new JPanel();
		pannello.setLayout(new GridLayout(15, 2));
		clienti=new JLabel("Clienti registrati:");
		pannello.add(clienti);
		numClienti=new JTextField(5);
		numClienti.setEditable(false);
		pannello.add(numClienti);
		clientiAnno=new JLabel("Clienti Anno Corrente "+annoCorrente);
		pannello.add(clientiAnno);
		numClientiAnno=new JTextField(5);
		numClientiAnno.setEditable(false);
		pannello.add(numClientiAnno);
		clientiAnnoP=new JLabel("Clienti Scorso Anno "+annoPrecedente);
		pannello.add(clientiAnnoP);
		numClientiAnnoP=new JTextField(5);
		numClientiAnnoP.setEditable(false);
		pannello.add(numClientiAnnoP);
		clientiProv=new JLabel("Clienti Provincia CS:");
		pannello.add(clientiProv);
		numClientiProv=new JTextField(5);
		numClientiProv.setEditable(false);
		pannello.add(numClientiProv);
		try {
			rs=GraficaHotel.database.stat.executeQuery("SELECT count(*) FROM CLIENTI");
			rs.next();
			numClienti.setText(rs.getString(1));
			rs=GraficaHotel.database.stat.executeQuery("select count(*) from clienti where datadiarrivo like '%"+annoCorrente+"'");
			rs.next();
			numClientiAnno.setText(rs.getString(1));
			rs=GraficaHotel.database.stat.executeQuery("select count(*) from clienti where datadiarrivo like '%"+annoPrecedente+"'");
			rs.next();
			numClientiAnnoP.setText(rs.getString(1));
			rs=GraficaHotel.database.stat.executeQuery("SELECT count(*) from clienti where provinciadiresidenza='CS'");
			rs.next();
			numClientiProv.setText(rs.getString(1));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		add(pannello);
	}
	
}
